#!/bin/bash
export SVN_WORKING_COPY="/var/www/vhosts/yeox.de/private/motsangria"
export WEBAPP_NAME="motsangria"

#stop tomcat
$CATALINA_HOME/bin/shutdown.sh
killall java

#update svn working copy
cd $SVN_WORKING_COPY
svn update

#generate war archive
grails upgrade -force
grails prod war
rm -Rf $CATALINA_HOME/webapps/$WEBAPP_NAME*

#delete old logs and copy webapp to tomcat webapp dir
rm -Rf $CATALINA_HOME/logs/*
cp ./$WEBAPP_NAME-$(cat application.properties | grep "app.version" | awk '{split($0,a,"="); split(a[2],b,"\r"); print b[1]}').war $CATALINA_HOME/webapps/$WEBAPP_NAME.war

#restart tomcat
$CATALINA_HOME/bin/startup.sh
#End of script
